package com.hxzy.projectssmplus.vo;

import java.util.HashMap;

/**
 * 不是分页的数据返回
 * {
 *   "code": 0,
 *   "msg": "",
 *   "data": 数据
 * }
 */
public class AjaxResult extends HashMap<String,Object> {

    //输出编码 键
    private final static String CODE="code";

    //消息内容 键
    private final static String  MSG="msg";

    private AjaxResult(){

    }

    /**
     * 成功
     * @return
     */
    public static AjaxResult success(){
        AjaxResult  ajaxResult=new AjaxResult();
        ajaxResult.put(CODE,0);
        ajaxResult.put(MSG,"OK");
        return ajaxResult;
    }

    /**
     * 成功
     * @param msg
     * @return
     */
    public static AjaxResult success(String msg){
        AjaxResult  ajaxResult=new AjaxResult();
        ajaxResult.put(CODE,0);
        ajaxResult.put(MSG,msg);
        return ajaxResult;
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static AjaxResult success_data(Object data){
        AjaxResult  ajaxResult=new AjaxResult();
        ajaxResult.put(CODE,0);
        ajaxResult.put(MSG,"OK");
        ajaxResult.put("data", data);
        return ajaxResult;
    }

    /**
     * 失败
     * @param msg
     * @return
     */
    public static AjaxResult error(String msg){
        AjaxResult  ajaxResult=new AjaxResult();
        ajaxResult.put(CODE,500);
        ajaxResult.put(MSG,msg);
        return ajaxResult;
    }
}
